// views/index/shop/mailservice/second/index.js
var BASE_URL = getApp().globalData.BASE_URL
var area = require('../../../../../../utils/area');
var util = require('../../../../../../utils/util');

import Notify from '../../../../../../miniprogram_npm/@vant/weapp/notify/notify';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: "",
    areaList: area.default,
    showarea: false, //地区遮罩
    showmudi: false, //目的遮罩
    area: '',
    name: '',
    name_pinyin: '',
    phone: '',
    wechat: '',
    address: '',
    dizhilist: '',
    userid: '',
    dizhiid: '',
    mudi: '不确定',
    didian: '不确定',
    useremail: '',
    du_time: 'yyyy/mm/日',
    openjiudupop: false,
    openappointment_time: false,
    nowtime: "",
    columns: '',
    pop_type: '',
    appointment: 1,
    appointment_time: 'yyyy/mm/日',
    price: '',
    list:'',
    type:""
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id,
      type:options.type
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var _this = this
    if (util.iflogin()) {
      _this.getdizhilist()
    }
  },
  //获得地址
  getdizhilist: function () {
    var userinfo = wx.getStorageSync("USER")
    var _this = this
    wx.request({
      url: `${BASE_URL}/visa/visadata`,
      method: "POST",
      data: {
        cate:_this.data.type,
        uid: userinfo.id,
        type: 'xiaochengxv',
      },
      header: {
        'Content-Type': 'application/json' //GET方式是这个
      },
      success(res) {
        console.log(res)
        res.data.list.info = JSON.parse(res.data.list.info)
        res.data.list.other_info = JSON.parse(res.data.list.other_info)
        _this.setData({
          name: res.data.list.info.sname,
          name_pinyin: res.data.list.info.pingyin,
          phone: res.data.list.info.dianhua,
          wechat: res.data.list.info.wechat,
          area: res.data.list.info.qvyu,
          address: res.data.list.info.dizhi,
          useremail: res.data.list.email,
          mudi: res.data.list.other_info.num_trips+'人',
          didian: res.data.list.other_info.stay_days+'天',
          du_time: res.data.list.other_info.travel_date,
          beizhu: res.data.list.other_info.beizhu==''?'无备注':res.data.list.other_info.beizhu,
          price: res.data.list.amount,
          email: res.data.list.email,
          list:res.data.list
        })
      }
    })
  },


  //填写信息的下一步按钮
  gothird: function () {
    var userinfo = wx.getStorageSync("USER")
    var _this = this
    wx.request({
      url: `${BASE_URL}/visa/onesave`,
      method: "POST",
      data: {
        id: _this.data.id,
        uid: userinfo.id,
        openid: userinfo.openid,
        type: 'xiaochengxv',
      },
      header: {
        'Content-Type': 'application/json' //GET方式是这个
      },
      success(res) {
        console.log(res)
        wx.navigateTo({
          url: `../../paypage/index?id=${res.data.id}`,
        })
      }
    })
  },














  //手机号正则
  codeVerification: function (phone) {
    let phoneCodeVerification = /^[1][3,4,5,7,8][0-9]{9}$/;
    return phoneCodeVerification.test(phone);
  },
  //英文字母正则
  ifenglish: function (pinyin) {
    let ifenglish = /^[A-Za-z]+$/;
    return ifenglish.test(pinyin);
  },
  //汉字正则
  ifhanzi: function (pinyin) {
    let ifhanzi = /^[\u4e00-\u9fa5]+$/;
    return ifhanzi.test(pinyin);
  },
  //微信号正则
  ifwewhat: function (pinyin) {
    let ifwewhat = /^[0-9a-zA-Z]*$/g;
    return ifwewhat.test(pinyin);
  },
  //邮箱验证
  ifemail: function (email) {
    let ifemail = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    return ifemail.test(email);
  },



  //打开地区选择遮罩层
  open_area: function (e) {
    this.setData({
      showarea: true
    })
  },
  //选择好地区并关闭地区选择器遮罩呈
  changeuserarea: function (e) {
    console.log(e)
    var str = []
    e.detail.values.forEach((item, index) => {
      if (item) {
        str.push(item.name)
      }
    })
    str = str.join('--')
    this.setData({
      showarea: false,
      area: str
    })
  },
  //关闭遮罩
  closeuserarea: function () {
    this.setData({
      showarea: false
    })
  },

})